package htmodels

import (
	"github.com/astaxie/beego/orm"
	"shuxianghui/models"
)
func HTCommentAdd(comment *models.Comment) error {
	o := orm.NewOrm()
	_, err := o.Insert(comment)
	return err
}

func HTCommentGetDetail(comment *models.Comment) error {
	o := orm.NewOrm()
	return o.Read(comment)
}

func HTCommentGetCount(search string, searchFiled string , Type int) (int64, error) {
	o := orm.NewOrm()
	m := models.Comment{}
	count, err := o.QueryTable(m.TableName()).Filter(m.FN_Type(), Type).Filter(searchFiled + "__icontains", search).Count()
	return count, err
}

func HTCommentGetList(comments *[]models.Comment, fields []string , Type int, offset int64, limit int, search string, searchFiled string, orderby string) error {
	o := orm.NewOrm()
	m := models.Comment{}
	_, err := o.QueryTable(m.TableName()).Filter(m.FN_Type(), Type).Filter(searchFiled + "__icontains", search).OrderBy(orderby).Offset(offset).Limit(limit).All(comments, fields...)
	return err
}

func HTCommentDelete(Ids []int64) (int64, error) {
	o := orm.NewOrm()
	m := models.Comment{}
	count, err := o.QueryTable(m.TableName()).Filter("Id" + "__in", Ids).Delete()
	return count, err
}
func HTCommentUpdate(comment *models.Comment) error {
	o := orm.NewOrm()
	_, err := o.Update(comment)
	return err
}